package com.ramos.kuaixiao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ramos.kuaixiao.R;
import com.ramos.kuaixiao.entity.DataReport;

import java.util.List;

public class DataReportAdapter extends BaseAdapter {

    private List<DataReport> mList;
    private Context context;

    static class ViewHolder {
        TextView tvName;
        TextView tvPrice;
        TextView tvCount;
    }

    public DataReportAdapter(Context context, List<DataReport> list) {
        this.context = context;
        this.mList = list;
    }

    public void refresh(List<DataReport> data) {
        mList = data;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.list_data_report, null);
            holder = new ViewHolder();
            holder.tvName = convertView.findViewById(R.id.name);
            holder.tvPrice = convertView.findViewById(R.id.price);
            holder.tvCount = convertView.findViewById(R.id.count);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tvName.setText(mList.get(position).getCustmerName());
        holder.tvPrice.setText(mList.get(position).getOrderTotalPrice() + "");
        holder.tvCount.setText(mList.get(position).getTotal() + "");
        return convertView;
    }
}